import 'package:get/get.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/http/http_util_service.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:xinxuan/vo/common_vo/common_seckill_activity_products_item_vo.dart';
import 'package:xinxuan/vo/create_seckill_order_vo.dart';
import 'package:xinxuan/vo/seckill_activity_products_detail_vo.dart';

class SeckillDetailPageController extends GetxController {

  final CommonPageController commonPageController = Get.find();
  
  /// 抢购详情
  var seckillDetailData = CommonSeckillActivityProductsItemVo(id: 0, price: '', title: '').obs;

  @override
  void onReady() {
    Map<String, dynamic> argumentsMap = Get.arguments;
    int id = argumentsMap['id'];
    getSeckillDetail(id);
    super.onReady();
  }

  /// 获取抢购商品详情
  getSeckillDetail(int id) async {
    SeckillActivityProductsDetailVo seckillDetailVo = await HttpUtilService.getSeckillActivityProductsDetail(id: id);
    seckillDetailData.value = seckillDetailVo.data!;
    update();
  }

  /// 提交抢购订单
  submitSeckillOrder() async {
    if (seckillDetailData.value.id! <= 0) {
      return;
    }
    CreateSeckillOrderVo? submitSeckillOrderVo = await HttpUtilService.createSeckillOrder(productId: seckillDetailData.value.id!);
    if (submitSeckillOrderVo != null) {
      // Get.toNamed(
      //   '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAY_PAGE}',
      //   arguments: {
      //     'payAmount': submitSeckillOrderVo.data!.payableAmount!,
      //     'orderSn': submitSeckillOrderVo.data!.orderSn
      //   }
      // );
      Get.toNamed(
        '${AppRouters.COMMON_PAGE}${AppRouters.SECKILL_ORDER_PAGE}${AppRouters.SECKILL_ORDER_DETAIL_PAGE}',
        arguments: {
          'seckillOrderId': submitSeckillOrderVo.data!.id!,
          'isOrderPage': false,
          'title': submitSeckillOrderVo.data!.statusStr
        }
      );
    }
  }
  
}